package Z03JiHeKuangJia.QiTaJiHe.T04HashSet;


import java.util.*;

public class TestHashSet {}

class Test{
    public static void main(String[] args) {
        HashSet<String> name = new HashSet<String>();
        name.add("Gereen");
        System.out.println(name);

        name.add("Gereen");
        System.out.println(name);
    }
}

class Tese1{
    public static void main(String[] args) {
        HashSet<Integer> number = new HashSet<Integer>();

        number.add(9);
        number.add(5);
        number.add(1);

        System.out.println(number);
    }
}

class Test2{
    public static void main(String[] args) {
        HashSet<Integer> number = new HashSet<Integer>();
        for (int i = 0 ; i < 20 ; i++){
            number.add(i);
        }

        for (Iterator<Integer> iterator = number.iterator();iterator.hasNext();){
            Integer i = (Integer) iterator.next();
            System.out.println(i);
        }

        for (Integer i : number){
            System.out.println(i);
        }
    }
}

class Test3<E>
        extends AbstractSet<E>
        implements Set<E>,Cloneable,
        java.io.Serializable
    {
    private HashMap<E, Object> map;
    private static final Object PRESENT = new Object();
    public Test3(){
        map = new HashMap<E, Object>();
    }

    public boolean add(E e){
        return map.put(e , PRESENT) == null ;
    }

public void clear(){
        map.clear();
}


     @Override
     public Iterator<E> iterator() {
         return map.keySet().iterator();
     }

     @Override
     public int size() {
         return map.size();
     }
 }
